package electionCtrl;

import javax.xml.stream.XMLStreamException;

import xml.MockVotingXMLReader;
import xml.MockVotingXMLWriter;


/**
 * The vote object.
 * This is an immutable object.
 * @author Nathan Ong
 * @author Isaac Rudich
 */
public final class Vote
{
	public final Candidate candidate;

	/**
	 * The constructor.
	 * @param c takes in a Candidate who is being voted for.
	 */
	public Vote(final Candidate c)
	{
		this.candidate = c;
	}
	
	public Vote(final MockVotingXMLReader reader) throws XMLStreamException {
		this(new Candidate(reader));
	}	
	
	public void writeToXML(final MockVotingXMLWriter writer) throws XMLStreamException {
		writer.writeStartElement("Vote");
		writer.pushHierarchy();
		writer.writeNewline();
		writer.writeTag("Name",this.candidate.name);
		writer.writeTag("Seat",this.candidate.seat.toString());
		writer.writeTag("Party",this.candidate.party);
		writer.pullHierarchy();
		writer.writeEndElement();
	}
	
	public String toString()
	{
		return this.candidate.toString();
	}
}